//package com.santiao.youxiang.ui.activity
//
//import android.annotation.SuppressLint
//import android.app.Activity
//import android.app.AlertDialog
//import android.app.DownloadManager
//import android.content.BroadcastReceiver
//import android.content.Context
//import android.content.Intent
//import android.content.IntentFilter
//import android.content.pm.PackageManager
//import android.graphics.Color
//import android.graphics.drawable.ColorDrawable
//import android.net.Uri
//import android.os.Build
//import android.os.Bundle
//import android.os.Environment
//import android.text.Spannable
//import android.text.SpannableString
//import android.text.TextPaint
//import android.text.method.LinkMovementMethod
//import android.text.style.ForegroundColorSpan
//import android.text.style.URLSpan
//import android.util.Log
//import android.view.View
//import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
//import android.widget.LinearLayout
//import android.widget.TextView
//import android.widget.Toast
//import androidx.activity.ComponentActivity
//import androidx.annotation.RequiresApi
//import androidx.appcompat.app.AppCompatActivity
//import androidx.core.content.ContextCompat
//import com.gyf.immersionbar.ImmersionBar
//import com.itheima.wheelpicker.WheelPicker
////import com.lazyliuzy.commonui.utils.lzy.LZYADSUtils
//import kotlin.apply
////import kotlin.jvm.java
//import com.santiao.youxiang.R
//import com.santiao.youxiang.database.shebaoBill
//import com.santiao.youxiang.database.yibaoBill
//import com.santiao.youxiang.databinding.ActivityCreateBiilBinding
//import com.santiao.youxiang.ext.thrillClickListener
//import java.util.Calendar
//
//class AddBillActivity: AppCompatActivity() {
//    private lateinit var binding: ActivityCreateBiilBinding
////    private lateinit var lzyadsUtils: com.lazyliuzy.commonui.utils.lzy.LZYADSUtils
//var type_a="" //1 医保 2：社保
//
//    var slePosition=1
//
//    var struri=""
//    // 在类顶部定义
//    val REQUEST_STORAGE_PERMISSION = 1001  // 可以是任意唯一整数
//
//    companion object {
//        // 定义一个静态方法来创建Intent
//        // 定义一个静态方法来创建Intent并携带uri数据
//        fun startActivity(context: Context?, type: String) {
//
//            val intent = Intent(context, AddBillActivity::class.java).apply {
//
//                putExtra("type", type)
//
//            }
//
//            context!!.startActivity(intent)
//        }
//
//    }
//
//    override fun onCreate(savedInstanceState: Bundle?) {
//        super.onCreate(savedInstanceState)
//        binding = ActivityCreateBiilBinding.inflate(layoutInflater)
//        setContentView(binding?.root)
//        type_a= intent.getStringExtra("type").toString()
//        ImmersionBar.with(this)
//            .transparentStatusBar()
//            .init()
//        initViews(type_a)
//    }
//
//
//
//     fun initViews(type: String) {
////        initad()
//
//         initclick()
//
//
//        binding.ivBack.setOnClickListener { onBackPressed() }
//         when(type){
////             "1"->{
////                 binding.topBar.tvTitle.text ="最低工资"
////             }
//             "2"->{
//                 //社保
//                 binding.ivItem1.setImageResource(R.drawable.ic_shebao_bg5)
//                 binding.ivItem2.setImageResource(R.drawable.ic_shebao_bg2)
//                 binding.ivItem3.setImageResource(R.drawable.ic_shebao_bg3)
//                 binding.ivItem4.setImageResource(R.drawable.ic_shebao_bg4)
//                 binding.tvItem1.text="养老保险"
//                 binding.tvItem2.text="生育保险"
//                 binding.tvItem3.text="失业保险"
//                 binding.tvItem4.text="工伤保险"
////                 binding.ivBg.setImageResource(R.drawable.ic_mk_bg2)
//             }
////             "3"->{
////                 binding.topBar.tvTitle.text ="药品目录"
////                 binding.ivBg.setImageResource(R.drawable.ic_mk_bg3)
////                 binding.tvFile.visibility=View.VISIBLE
////                 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
////                     initV()
////                 }
////             }
////             "4"->{
////                 binding.topBar.tvTitle.text ="生育津贴"
////                 binding.ivBg.setImageResource(R.drawable.ic_mk_bg4)
////                 binding.llContent.setBackgroundColor(Color.WHITE)
////             }
//
//         }
//
//
//    }
//
//    fun initclick(){
//
//        binding.ivItem1.thrillClickListener {
//            switchItem(1)
//        }
//
//        binding.ivItem2.thrillClickListener {
//            switchItem(2)
//        }
//
//
//        binding.ivItem3.thrillClickListener {
//            switchItem(3)
//        }
//
//
//        binding.ivItem4.thrillClickListener {
//            switchItem(4)
//        }
//
//        binding.ivMore.thrillClickListener {
//            showDatePicker()
//        }
//
//        binding.tvTitle2.thrillClickListener {
//            if (binding.etAmout.text.isNullOrBlank()||binding.tvDate.text.isNullOrBlank()){
//                Toast.makeText(this@AddBillActivity,"金额或日期缺失，不能保存", Toast.LENGTH_LONG).show()
//            }else{
//                saveBill()
//            }
//
//        }
//
//
//    }
//
//    fun switchItem(position: Int) {
//        slePosition=position
//        when (type_a) {
//            "1" -> {
//                binding.ivItem1.setImageResource(R.drawable.ic_yibao_bg1)
//                binding.ivItem2.setImageResource(R.drawable.ic_yibao_bg2)
//                binding.ivItem3.setImageResource(R.drawable.ic_yibao_bg3)
//                binding.ivItem4.setImageResource(R.drawable.ic_yibao_bg4)
//
//                when (position) {
//                    1 -> binding.ivItem1.setImageResource(R.drawable.ic_yibao_bg5)
//                    2 -> binding.ivItem2.setImageResource(R.drawable.ic_yibao_bg6)
//                    3 -> binding.ivItem3.setImageResource(R.drawable.ic_yibao_bg7)
//                    4 -> binding.ivItem4.setImageResource(R.drawable.ic_yibao_bg8)
//                    else -> {
//                        // 其他情况可以设置默认图片，或者不做任何事情
//                    }
//
//                }
//
//            }
//
//            "2" -> {//社保 重置再更新ui
//                binding.ivItem1.setImageResource(R.drawable.ic_shebao_bg1)
//                binding.ivItem2.setImageResource(R.drawable.ic_shebao_bg2)
//                binding.ivItem3.setImageResource(R.drawable.ic_shebao_bg3)
//                binding.ivItem4.setImageResource(R.drawable.ic_shebao_bg4)
//
//                when (position) {
//                    1 -> binding.ivItem1.setImageResource(R.drawable.ic_shebao_bg5)
//                    2 -> binding.ivItem2.setImageResource(R.drawable.ic_shebao_bg6)
//                    3 -> binding.ivItem3.setImageResource(R.drawable.ic_shebao_bg7)
//                    4 -> binding.ivItem4.setImageResource(R.drawable.ic_shebao_bg8)
//                    else -> {
//                        // 其他情况可以设置默认图片，或者不做任何事情
//                    }
//
//                }
//
//            }
//
//        }
//    }
//
//    fun saveBill(){
//
//        when (type_a){
//            "1"->{
//                var billob= yibaoBill(billType = slePosition.toString(),billAmount=binding.etAmout.text.toString().trim(),BillDate=binding.tvDate.text.toString())
//
//                Log.e( "saveBill: ", "billType "+slePosition+" "+binding.etAmout.text.toString()+"  "+binding.tvDate.text.toString())
//                try {
//                    billob.save()
//                }catch (e: Exception){
//                    Log.e( "saveBill: ", e.toString())
//                }
//                if (billob.save()){
//                    Toast.makeText(this@AddBillActivity,"保存成功", Toast.LENGTH_LONG).show()
//                    onBackPressed()
//                }else Toast.makeText(this@AddBillActivity,"保存失败", Toast.LENGTH_LONG).show()
//            }
//
//            "2"->{
//                var billob= shebaoBill(billType = slePosition.toString(),billAmount=binding.etAmout.text.toString().trim(),BillDate=binding.tvDate.text.toString())
//                if (billob.save()){
//                    Toast.makeText(this@AddBillActivity,"保存成功", Toast.LENGTH_LONG).show()
//                    onBackPressed()
//                }else Toast.makeText(this@AddBillActivity,"保存失败", Toast.LENGTH_LONG).show()
//            }
//
//        }
//
//    }
//
//    fun getMaxDayOfMonth(year: Int, month: Int): Int {
//        val selectedCal = Calendar.getInstance().apply {
//            set(Calendar.YEAR, year)
//            set(Calendar.MONTH, month - 1) // 月份从 0 开始
//        }
//
//        val currentCal = Calendar.getInstance()
//
//        val isSameYear = selectedCal.get(Calendar.YEAR) == currentCal.get(Calendar.YEAR)
//        val isSameMonth = isSameYear && selectedCal.get(Calendar.MONTH) == currentCal.get(Calendar.MONTH)
//
//        return if (isSameMonth) {
//            currentCal.get(Calendar.DAY_OF_MONTH) // 当前月份，只显示到今天
//        } else {
//            selectedCal.getActualMaximum(Calendar.DAY_OF_MONTH) // 非当前月份，显示全月天数
//        }
//    }
//
//
//    @SuppressLint("SuspiciousIndentation")
//    private fun showDatePicker() {
//        val calendar = Calendar.getInstance()
//        val currentYear = calendar.get(Calendar.YEAR)
//        val currentMonth= calendar.get(Calendar.MONTH)
////        val currentDay= calendar.get(Calendar.DAY_OF_MONTH)
//
//        // 年份列表
//        val years = (currentYear - 3 .. currentYear).map { it.toString() }
//
//        // 月份列表
//        val months = (1..currentMonth+1).map { String.format("%02d", it) }
//
//        // 日期列表与更新逻辑
//        val days = mutableListOf<String>()
//        val updateDays: (Int) -> Unit = { month ->
//            days.clear()
//            var maxDay=0
//            val cal = Calendar.getInstance().apply { set(Calendar.MONTH, month - 1) }
//            if (month - 1==currentMonth){
//                maxDay=   calendar.get(Calendar.DAY_OF_MONTH)
//            }else maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH)
//
//
//            for (i in 1..maxDay) days.add(String.format("%02d", i))
//        }
//
//        // 主题色和默认色
//        val primaryColor = ContextCompat.getColor(this, R.color.Theme)
//        val normalColor  = ContextCompat.getColor(this, R.color.white)
//
//        // 1) 创建并样式化三个 WheelPicker
//        val yearPicker = WheelPicker(this).apply {
//            setData(years)
//            setSelectedItemPosition(years.size - 1)
//            // 以下两行加上去即可让选中项变色
//            setItemTextColor(normalColor)
//            setSelectedItemTextColor(primaryColor)
//        }
//        val monthPicker = WheelPicker(this).apply {
//            setData(months)
//            setSelectedItemPosition(calendar.get(Calendar.MONTH))
//            setItemTextColor(normalColor)
//            setSelectedItemTextColor(primaryColor)
//        }
//        val dayPicker = WheelPicker(this).apply {
//            updateDays(calendar.get(Calendar.MONTH) + 1)
//            setData(days)
//            setSelectedItemPosition(calendar.get(Calendar.DAY_OF_MONTH) - 1)
//            setItemTextColor(normalColor)
//            setSelectedItemTextColor(primaryColor)
//        }
//
//        // 2) 当月改变时，更新 dayPicker
//        monthPicker.setOnItemSelectedListener { _, _, pos ->
//            updateDays(pos + 1)
//            dayPicker.setData(days)
//            dayPicker.setSelectedItemPosition(0)
//        }
//
//        // 3) 把三个 picker 放到同一个 LinearLayout
//        val container = LinearLayout(this).apply {
//            orientation = LinearLayout.HORIZONTAL
//            val lp = LinearLayout.LayoutParams(0, WRAP_CONTENT, 1f)
//            addView(yearPicker, lp)
//            addView(monthPicker, lp)
//            addView(dayPicker, lp)
//            setPadding(20, 20, 20, 20)
//        }
//
//        // 4) 用 container 一次性 setView
//     var  dialog=  AlertDialog.Builder(this, R.style.MyAlertDialogTheme)
//            .setTitle("选择日期")
//            .setView(container)
//            .setPositiveButton("确定") { _, _ ->
//                val y = years[yearPicker.currentItemPosition]
//                val m = months[monthPicker.currentItemPosition]
//                val d = days[dayPicker.currentItemPosition]
//                binding.tvDate.text = "${y}年${m}月${d}日"
//            }
//            .setNegativeButton("取消", null)
//            .show()
//
//        // 修改标题颜色
////        dialog.findViewById<TextView>(android.R.id.title)?.setTextColor(
////            ContextCompat.getColor(this, R.color.white)
////        )
//
//
//
//// 修改对话框背景颜色
////        dialog.window?.backgr(R.drawable.dialog_bg) // 或颜色值
//// 或者直接设置颜色：
////        dialog.window?.setBackgroundDrawable(ColorDrawable(ContextCompat.getColor(this, R.color.black)))
//
//    }
//
//
//
//
//    fun   initad() {
////        myContext = requireContext()
////        lzyadsUtils=
////            com.lazyliuzy.commonui.utils.lzy.LZYADSUtils("Task1Activity", this@Task1Activity)
////        com.lazyliuzy.commonui.utils.lzy.LZYADSUtils.loadSimpleAd1(com.lazyliuzy.commonui.databinding.ActivityTask1Binding.flAd)
////        com.lazyliuzy.commonui.utils.lzy.LZYADSUtils.showAdCpTurn()
//
//    }
//
//}